//
//  CircleCollectionViewCell.m
//  MeterMart
//
//  Created by ENERGY on 2018/9/17.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "CircleCollectionViewCell.h"
#define circleImgW (SCREEN_WIDTH - 70/WIDTH_6_SCALE)/5
@interface CircleCollectionViewCell ()
@property (nonatomic, strong)UIImageView * circleImg;
@property (nonatomic, strong)UILabel * titleLab;
@property (nonatomic, strong)NSString * iconID;
@end

@implementation CircleCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.circleImg];
        [self.contentView addSubview:self.titleLab];
        __weak typeof (self)weakSelf = self;
        [self.circleImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.width.mas_equalTo(circleImgW);
            make.top.centerX.equalTo(weakSelf.contentView);
        }];
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(weakSelf.circleImg);
            make.top.equalTo(weakSelf.circleImg.mas_bottom).mas_offset(5/WIDTH_6_SCALE);
            make.bottom.equalTo(weakSelf.contentView.mas_bottom).mas_offset(-3/WIDTH_6_SCALE);
        }];
    }return self;
}

#pragma mark - init
- (UIImageView *)circleImg{
    if (!_circleImg) {
        _circleImg = [[UIImageView alloc] init];
        _circleImg.image = [UIImage imageNamed:@"YimiPlaceHolderCircle"];
        _circleImg.backgroundColor = [UIColor clearColor];
        _circleImg.layer.cornerRadius = circleImgW/2;
        _circleImg.layer.masksToBounds = YES;
    }return _circleImg;
}
- (UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = DEF_FontSize_12;
        _titleLab.textColor = [UIColor blackColor];
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.text = @"类别";
    }return _titleLab;
}

- (void)setModel:(NSDictionary *)model{
    _model = model;
    [self.circleImg sd_setImageWithURL:[NSURL URLWithString:model[@"imgurl"]] placeholderImage:[UIImage imageNamed:@"YimiPlaceHolderCircle"]];
    self.titleLab.text = model[@"name"];
    self.iconID = model[@"iconid"];
}
@end
